//
//  HWGameOpenServiceCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/3/9.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWGameOpenServiceCell: UITableViewCell {
    var logoImageView:UIImageView!
    var nameLabel:UILabel!
    var serviceName:UILabel!
    var timeLabel:UILabel!
    var detailLabel:UILabel!
    var model:HWGameOpenServiceListModel?{
        didSet {
            logoImageView.sd_setImage(with: URL(string: model?.icon ?? ""), completed: nil)
            nameLabel.text = model?.name
            serviceName.text = model?.server_name
            timeLabel.text = "\(model?.time1 ?? "")" + " " + "\(model?.time2 ?? "")"
        }
    }
    
    class func cellWithTableView(tableView:UITableView) -> (HWGameOpenServiceCell) {
        let reUse:String = "HWGameOpenServiceCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWGameOpenServiceCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWGameOpenServiceCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        logoImageView = UIImageView()
        logoImageView.backgroundColor = .clear
        logoImageView.layer.cornerRadius = 10*widthScale
        logoImageView.layer.masksToBounds = true
        logoImageView.contentMode = .scaleAspectFill
        contentView.addSubview(logoImageView)
        
        nameLabel = HWLabel.createBoldLabel(title: "", color: "#444444", font: 14*widthScale)
        nameLabel.numberOfLines = 1
        contentView.addSubview(nameLabel)
        
        serviceName = HWLabel.createLabel(title: "", color: "#444444", font: 12*widthScale)
        contentView.addSubview(serviceName)
        
        timeLabel = HWLabel.createLabel(title: "", color: "#888888", font: 10*widthScale)
        contentView.addSubview(timeLabel)
        
        detailLabel = HWLabel.createLabel(title: "详情", color: "#FFFFFF", font: 12*widthScale)
        detailLabel.backgroundColor = .colorWithHexString(hexString: "#F87706")
//        detailLabel.layer.borderColor = UIColor.colorWithHexString(hexString: "#FE6A4C").cgColor
//        detailLabel.layer.borderWidth = 1*widthScale
        detailLabel.layer.cornerRadius = 11*widthScale
        detailLabel.layer.masksToBounds = true
        detailLabel.textAlignment = .center
        contentView.addSubview(detailLabel)
        
    }
    
    func initFrame() -> Void {
        
        logoImageView.snp.makeConstraints { make in
            make.left.equalTo(20*widthScale)
            make.top.equalTo(10*widthScale)
            make.width.height.equalTo(52*widthScale)
            make.bottom.equalTo(-10*widthScale)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(logoImageView.snp.right).offset(6*widthScale)
            make.top.equalTo(logoImageView)
            make.right.equalTo(detailLabel.snp.left).offset(-5)
        }
        
        serviceName.snp.makeConstraints { make in
            make.centerY.equalTo(logoImageView)
            make.left.equalTo(nameLabel)
        }
        
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(nameLabel)
            make.bottom.equalTo(logoImageView)
        }
        
        detailLabel.snp.makeConstraints { make in
            make.centerY.equalTo(logoImageView)
            make.right.equalTo(-20*widthScale)
            make.width.equalTo(50*widthScale)
            make.height.equalTo(22*widthScale)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
